<script setup>
import {useCategoryStore} from '@/store/categoryStore'

const categoryStore = useCategoryStore()


</script>

<template>
  <div class="home-menu">
    <ul class="menu">
      <li v-for="item in categoryStore.categoryList" :key="item.id">
        <router-link to="/">{{ item.name }}</router-link>
        <RouterLink to="/" v-for="i in item.children.slice(0, 2)" :key="i.id">{{ i.name }}</RouterLink>

        <!-- 弹层layer位置 -->
        <div class="layer">
          <h4>分类推荐 <small>根据您的购买或浏览记录推荐</small></h4>
          <ul>
            <li v-for="i in item.goods" :key="i.id">
              <router-link :to="`/detail/${i.id}`">
                <img :src="i.picture" alt=""/>
                <div class="info">
                  <p class="name" :title="i.name">
                    {{ i.name }}
                  </p>
                  <p class="desc" :title="i.desc">{{ i.desc }}</p>
                  <p class="price"><i>¥</i>{{ i.price }}</p>
                </div>
              </router-link>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="scss">
.home-menu {
  width: 220px;
  height: 500px;
  background: rgba(0, 0, 0, 0.75);
  position: absolute;
  z-index: 99;
  color: white;

  .menu {
    li {
      display: flex;
      align-items: center;
      padding-left: 20px;
      height: 55px;
      border-bottom: 1px solid rgba(80, 80, 80, 0.56);

      &:hover {
        background: #27ba9b;
        cursor: pointer;
      }

      a {
        margin-right: 5px;
        color: #fff;

        &:first-child {
          font-size: 16px;
        }
      }


      .layer {
        width: 1000px;
        height: 500px;
        background: rgba(255, 255, 255, 0.8);
        position: absolute;
        left: 220px;
        top: 0;
        display: none;
        padding: 0 15px;

        h4 {
          font-size: 20px;
          color: #27ba9b;
          height: 50px;
          padding: 10px 0;
          display: flex;
          align-items: center;

          small {
            font-size: 16px;
            margin-left: 15px;
            color: #666;
          }
        }

        ul {
          display: flex;
          flex-wrap: wrap;

          li {
            width: 310px;
            height: 130px;
            margin: 0 15px 15px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
            background: #fff;
            opacity: 0.8;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);

            &:hover {
              background: #e3f9f4;
            }

            &:nth-child(3n) {
              margin-right: 0;
            }

            a {
              display: flex;
              align-items: center;

              img {
                width: 95px;
                height: 95px;
              }

              .info {
                padding-left: 10px;
                line-height: 24px;

                //文本截断
                .name, .desc {
                  width: 160px; // 设置固定宽度
                  white-space: nowrap; // 防止文本换行
                  overflow: hidden; // 隐藏溢出的文本
                  text-overflow: ellipsis; // 显示省略号
                }

                .name {
                  font-size: 16px;
                  color: #666;
                }

                .desc {
                  font-size: 14px;
                  margin-top: 5px;
                  color: #999;
                }

                .price {
                  font-size: 18px;
                  color: #f60;
                  font-weight: bold;
                  margin-top: 10px;

                  i {
                    font-size: 16px;
                  }
                }
              }
            }
          }
        }
      }

      // 关键样式  hover状态下的layer盒子变成block
      &:hover {
        .layer {
          display: block;
        }
      }


    }
  }
}

</style>